{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0b559d6f",
   "metadata": {},
   "source": [
    "# 上周内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "865c7e4a",
   "metadata": {},
   "source": [
    "> 1. API阅读文档(考试)\n",
    "> 2. requests 请求(考试)\n",
    "> 3.百度通用图像识别"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca8be83d",
   "metadata": {},
   "source": [
    "# 本周内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "110210bc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678869632,bd9a9f03-d20c-4a5f-9ca4-0271cd5d3687', 'time_used': 363, 'faces': [{'face_token': '58bd7bc52cab792bfa58c482764a9ebf', 'face_rectangle': {'top': 323, 'left': 294, 'width': 450, 'height': 450}, 'attributes': {'gender': {'value': 'Female'}, 'age': {'value': 22}, 'smile': {'value': 1.885, 'threshold': 50.0}, 'headpose': {'pitch_angle': 2.860102, 'roll_angle': -4.950195, 'yaw_angle': 27.259079}, 'blur': {'blurness': {'value': 0.045, 'threshold': 50.0}, 'motionblur': {'value': 0.045, 'threshold': 50.0}, 'gaussianblur': {'value': 0.045, 'threshold': 50.0}}, 'emotion': {'anger': 0.002, 'disgust': 0.001, 'fear': 0.001, 'happiness': 0.002, 'neutral': 99.881, 'sadness': 0.107, 'surprise': 0.006}, 'facequality': {'value': 0.201, 'threshold': 70.1}, 'beauty': {'male_score': 61.0, 'female_score': 70.888}}}], 'image_id': 'RavTE6w5URecTj1XdvJ0Nw==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('nh.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2. 酬载准备\n",
    "payload = {\n",
    "    'api_key':'Jf_a6CJW0Y2iF5_d1yCVGsuFuO-VH0bM',\n",
    "    'api_secret':'bjFCWXf_4bCXl2jklNAOegBup_D8lXm2',\n",
    "    'image_base64':img,\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,emotion,blur,beauty'\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data = payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "67de10eb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8a1439e1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
